
package system.base;

import framework.core.*;
import system.data.*;
/*
	Author    :Jackey
	CreateTime:2008-02-15 13:29:25
*/
public class MenuInfoSrv extends IHandler
{

	public MenuInfoSrv() 
	{
		super();
	}
	private void deleteMenuInfo(DBConnection con,SrvContext context) throws Exception
	{
		String[] ids = context.getParameterValues("ids");
		MenuInfo obj = null;
		for(int i=0;i<ids.length;i++)
		{
			obj = MenuInfo.fetch(con,ids[i]);
			if(obj!=null) obj.delete(con);
		}
	}
	private void saveMenuInfo(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String id = context.getString("Id",null);
		MenuInfo obj;
		if((id==null)||(id.equals("")))   //add
		{
			obj = MenuInfo.fetch();
    	}
    	else                     //update
    	{
    		obj = MenuInfo.fetch(con,id);
    	}
		MenuInfoPageData data = (MenuInfoPageData)PageData.fromForm(context,MenuInfoPageData.class);
		context.setValue("MenuInfoPageData",data);
		obj.fill(data);
		obj.save(con);
	}
	private void listMenuInfo(DBConnection con,SrvContext context,String path) throws Exception
	{
		MenuInfoSearchEvent event = (MenuInfoSearchEvent)SearchEvent.fromForm(context,MenuInfoSearchEvent.class);
		context.setSessionValue("MenuInfoSearchEvent",event);
		context.setNextUrl(path+"MenuInfoList.jsp");
	}
	private void backMenuInfo(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"MenuInfoList.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		
		if(action_code.equalsIgnoreCase("listMenuInfo"))
		{
			listMenuInfo(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("viewMenuInfo"))
		{
			String id = context.getString("Id",null);
			MenuInfo obj = MenuInfo.fetch(con,id);
			context.setValue("MenuInfo",obj);
			context.setNextUrl(path+"MenuInfoView.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("deleteMenuInfo"))
		{
			context.setErrorUrl(path+"MenuInfoList.jsp");
			deleteMenuInfo(con,context);
			backMenuInfo(con,context,path);
			return;
		}
			
		if(action_code.equalsIgnoreCase("toAddMenuInfo"))
		{
			MenuInfo obj = MenuInfo.fetch();
			MenuInfoPageData data = (MenuInfoPageData)PageData.fromTable(obj,MenuInfoPageData.class);
			context.setValue("MenuInfoPageData",data);
			context.setNextUrl(path+"MenuInfoEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toUpdateMenuInfo"))
		{
			String id = context.getString("Id",null);
			MenuInfo obj = MenuInfo.fetch(con,id);
			MenuInfoPageData data = (MenuInfoPageData)PageData.fromTable(obj,MenuInfoPageData.class);
			context.setValue("MenuInfoPageData",data);
			context.setNextUrl(path+"MenuInfoEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toCopyMenuInfo"))
		{
			String id = context.getString("Id",null);
			MenuInfo obj = MenuInfo.copy(MenuInfo.fetch(con,id));
			MenuInfoPageData data = (MenuInfoPageData)PageData.fromTable(obj,MenuInfoPageData.class);
			context.setValue("MenuInfoPageData",data);
			context.setNextUrl(path+"MenuInfoEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("saveMenuInfo"))
		{
			context.setErrorUrl(path+"MenuInfoEdit.jsp");
			saveMenuInfo(con,context,loginContext);
			backMenuInfo(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveAndNewMenuInfo"))
		{
			context.setErrorUrl(path+"MenuInfoEdit.jsp");
			saveMenuInfo(con,context,loginContext);
			MenuInfo obj = MenuInfo.fetch();
			MenuInfoPageData data = (MenuInfoPageData)PageData.fromTable(obj,MenuInfoPageData.class);
			context.setValue("MenuInfoPageData",data);
			context.setNextUrl(path+"MenuInfoEdit.jsp");			
			return;
		}
		if(action_code.equalsIgnoreCase("backListMenuInfo"))
		{
			backMenuInfo(con,context,path);
			return;
		}
		
		//add by Jackey start

		//add by Jackey end

		Logger.throwException("MenuInfoSrv","unknown action_code="+action_code);
	}
}
